<template>
  <div>
    <PageTitle :title="titleName"></PageTitle>
    <div class="form-wrapper">
      <el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="机器数量" prop="class_name">
          <el-input v-model="ruleForm.machineCount" :readonly="true"></el-input>
        </el-form-item>        
        <el-form-item label="订单数量" prop="class_name">
          <el-input v-model="ruleForm.orderCount" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="退单数量" prop="class_name">
          <el-input v-model="ruleForm.backOrderCount" :readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="订单金额" prop="class_name">
          <el-input v-model="ruleForm.orderPrice" :readonly="true">
            <template slot="append">元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="商品库存" prop="class_name">
          <el-input v-model="ruleForm.Stock" :readonly="true"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div class="table-wrapper">
      <el-row>
        <el-col :span="24">
          <div class="title">
            <span class="text">
              {{ tableTitle }}
            </span>
          </div>
        </el-col>
      </el-row>
      <div class="switch">
        <el-switch
          v-model="tableType"
          active-text="退单"
          inactive-text="订单"
          inactive-color="#13ce66">
        </el-switch>
      </div>
      <div class="inner">
        <template v-if="!tableType">
          <DetailTable :thList="orderListTitle" :tableData="orderListData"></DetailTable>
        </template>
        <template v-else>
          <DetailTable :thList="backOrderListTitle" :tableData="backOrderListData"></DetailTable>
        </template>
      </div>
    </div>
    <div class="foot">
      <el-button type="primary" @click="$router.go(-1)">取消</el-button>
    </div>
  </div>
</template>

<script>
  import PageTitle from '@/components/pageTitle/PageTitle.vue'
  import DetailTable from '@/components/detailTable/DetailTable.vue'
  export default {
    name: 'GoodsTypeAdd',
    components: {
      PageTitle,
      DetailTable
    },
    mounted() {
      // this._get()
    },
    data() {
      return {
        ruleForm: {
          id: 1,
          title: '加盟商1',
          machineCount: '13',
          orderCount: '4',
          backOrderCount: '110',
          orderPrice: '250000.00',
          Stock: '500'
        },
        tableType: false,
        orderListTitle: [
          {
            lable: '订单号',
            prop: 'orderNum'
          },
          {
            lable: '订单金额',
            prop: 'price'
          },
          {
            lable: '订单状态',
            prop: 'state'
          }
        ],
        orderListData: [
          {
            orderNum: '123132',
            price: '60.00',
            state: '0'
          },
          {
            orderNum: '12dsada3132',
            price: '110.00',
            state: '1'
          },
          {
            orderNum: '1231jkll32',
            price: '199.00',
            state: '2'
          }
        ],
        backOrderListTitle: [
          {
            lable: '订单号',
            prop: 'orderNum'
          },
          {
            lable: '订单金额',
            prop: 'price'
          },
          {
            lable: '退单状态',
            prop: 'state'
          }
        ],
        backOrderListData: [
          {
          orderNum: 'poiweqeq',
          price: '59.00',
          state: '0'
          },
          {
          orderNum: 'poiweqeq',
          price: '189.00',
          state: '1'
          },
          {
          orderNum: 'poiweqeq',
          price: '68.00',
          state: '2'
          }
        ]
      }
    },
    computed: {
      titleName() {
        return '加盟商详情'
      },
      tableTitle() {
        return !this.tableType ? '被指派订单' : '被指派退单'
      }
    },
    methods: {
      async _get() {
        try{
          let {data: {code, data}} = await this.$axios({
            url: this.$api + '/v1/fication/surface' ,
            method: 'GET',
            params: {
              id: this.$route.params.id
            }
          })
          
          if(code == 0) {
            this.ruleForm.class_name = data[0].class_name
            this.ruleForm.state = data[0].state
          } else {
            this.$message.warning(data.message)
          }
        }catch(e){
          this.$message({
            type: 'error',
            message: e
          })
        }
      }
    }
  }
</script>

<style lang="scss" scoped>
  .table-wrapper {
    position: relative;
    margin: 30px 0;
    .title {
      // text-align: center;
      margin-bottom: 20px;
      padding: 0 20px;
    }
    .switch {
      position: absolute;
      top: 2px;
      left: 110px;
    }
    .inner {
      padding: 0 20px;
    }
  }
  .foot {
    padding-left: 20px;
  }
  
</style>
